package com.ltmonitor.app;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ltmonitor.entity.VehicleData;
import com.ltmonitor.jt808.service.IGpsDataService;
import com.ltmonitor.service.IBaseService;
import com.ltmonitor.service.IBatchInsertService;
import com.ltmonitor.service.ITerminalService;
import com.ltmonitor.service.IVehicleDataService;

/**
 * 加载spring文件，启动spring配置的服务
 *
 * @author admin
 */
public class ServiceLauncher {

    private static Logger logger = Logger.getLogger(ServiceLauncher.class);
    protected static ApplicationContext context = null;

    private static IGpsDataService GpsDataService;

    private static IVehicleDataService vehicleDataService;

    private static ITerminalService terminalService;


    public static IBatchInsertService batchInsertService;


    public static void launch() {

        // PropertyConfigurator.configure("log4j.properties");
        // context = new ClassPathXmlApplicationContext(
        // "classpath:applicationContextService.xml");
        context = new ClassPathXmlApplicationContext(new String[]{
                "spring.xml",
                "spring-hibernate.xml",
                "spring-jt808.xml",
                "spring-rmi-service.xml",
                //"applicationContext-quartz.xml",
                "spring-mybatis.xml",
                "spring-quartz.xml"
        });


        if (context == null) {
            int x = 0;
        }

        GpsDataService = (IGpsDataService) getBean("gpsDataService");
        terminalService = (ITerminalService) getBean("terminalService");
        vehicleDataService = (IVehicleDataService) getBean("vehicleDataService");

        batchInsertService = (IBatchInsertService) getBean("batchInsertService");
    }

    public static Object getBean(String beanID) {
        return context.getBean(beanID);
    }


    public static void main(String[] args) {
        try {
            ServiceLauncher.launch();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            System.out.println(ex.getStackTrace());
        }
    }

    public static IGpsDataService getGpsDataService() {
        return GpsDataService;
    }

    public static void setGpsDataService(IGpsDataService gpsDataService) {
        GpsDataService = gpsDataService;
    }


    public static IVehicleDataService getVehicleDataService() {
        return vehicleDataService;
    }

    public static void setVehicleDataService(IVehicleDataService vehicleDataService) {
        ServiceLauncher.vehicleDataService = vehicleDataService;
    }

    public static ITerminalService getTerminalService() {
        return terminalService;
    }

    public static void setTerminalService(ITerminalService terminalService) {
        ServiceLauncher.terminalService = terminalService;
    }


}
